﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using MT.eVotePRS.Model;
using MT.eVotePRS.Presentation;
using MT.eVotePRS.Presentation.Presenter;

namespace MT.eVotePRS.UI.UserControls
{
    public partial class RptHandsetTxn : UserControl, IViewRptTxn
    {
        #region IViewRptHandsetTxn

        IndividualReport _report;
        Status _txnStatus;

        public IndividualReport Report
        {
            get { return _report; }
        }

        public DateTime PeriodFrom
        {
            get { return dtPickerFrom.Value; }
        }

        public DateTime PeriodTo
        {
            get { return dtPickerTo.Value; }
        }

        public Status TxnStatus
        {
            get { return _txnStatus; }
        }
        
        public event EventHandler GenerateReport;

        #endregion

        public RptHandsetTxn()
        {
            InitializeComponent();
            this.btnGen.Click += OnGenerateReportClicked;
            rbtCheckIn.CheckedChanged += OnCheckedChanged;
            rbtCheckOut.CheckedChanged += OnCheckedChanged;
            rbtFault.CheckedChanged += OnCheckedChanged;
            rbtFF.CheckedChanged += OnCheckedChanged;
            rbtFound.CheckedChanged += OnCheckedChanged;
            rbtLost.CheckedChanged += OnCheckedChanged;
            rbtRepaired.CheckedChanged += OnCheckedChanged;

            _report = IndividualReport.Handset;
        }

        void OnGenerateReportClicked(object sender, EventArgs e)
        {
            EventHandler handlers = GenerateReport;
            if (handlers != null)
            {
                handlers(this, EventArgs.Empty);
            }
        }

        void OnCheckedChanged(object sender, EventArgs e)
        {
            if (rbtCheckIn.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_CheckIn;
            }
            else if (rbtCheckOut.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_CheckOut;
            }
            else if (rbtFault.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_Fault;
            }
            else if (rbtFF.Checked )
            {
                _txnStatus = Presentation.Util.Constants.Status_FoundnFault;
            }
            else if (rbtFound.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_Found;
            }
            else if (rbtLost.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_Lost;
            }
            else if (rbtRepaired.Checked)
            {
                _txnStatus = Presentation.Util.Constants.Status_Repaired;
            }
        }
    }
}
